package org.example.pms.service.impl;

import org.example.pms.domain.ClinicalObservation;
import org.example.pms.domain.EpitopeDetectionResult;
import org.example.pms.domain.Patient;
import org.example.pms.domain.VaccineResult;
import org.example.pms.domain.vo.PatientCaseVo;
import org.example.pms.mapper.ClinicalObservationMapper;
import org.example.pms.mapper.EpitopeDetectionResultMapper;
import org.example.pms.mapper.PatientMapper;
import org.example.pms.mapper.VaccineResultMapper;
import org.example.pms.service.PatientService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PatientServiceImpl implements PatientService {

    @Resource
    PatientMapper patientMapper;

    @Resource
    EpitopeDetectionResultMapper epitopeDetectionResultMapper;

    @Resource
    VaccineResultMapper vaccineResultMapper;

    @Resource
    ClinicalObservationMapper clinicalObservationMapper;

    @Override
    public List<Patient> getPatients(Patient patient) {

        List<Patient> patients = patientMapper.selectPatients();
        return patients;
    }

    @Override
    public Patient getPatient(Integer pid) {
        Patient patient = patientMapper.selectById(pid);

        return patient;
    }

    @Override
    public List<Patient> getPatients(Integer userId) {

        List<Patient> patients = patientMapper.selectPatientsByUid(userId);
        return patients;
    }

    @Override
    public PatientCaseVo getPatientCaseByPatientId(Integer patientId) {
        PatientCaseVo patientCaseVo = new PatientCaseVo();
        Patient patient = patientMapper.selectById(patientId);
        patientCaseVo.setUserId(patient.getUserId());
        patientCaseVo.setPatient(patient);
        List<EpitopeDetectionResult> epitopeDetectionResults = epitopeDetectionResultMapper.selectByPatientId(patientId);
        patientCaseVo.setEpitopeDetectionResults(epitopeDetectionResults);
        List<VaccineResult> vaccineResults = vaccineResultMapper.selectByPatientId(patientId);
        patientCaseVo.setVaccineResults(vaccineResults);
        List<ClinicalObservation> clinicalObservations = clinicalObservationMapper.selectByPatientId(patientId);
        patientCaseVo.setClinicalObservations(clinicalObservations);

        return patientCaseVo;
    }

    @Override
    public Integer savePatient(Patient patient) {

        Integer id = patientMapper.insertPatient(patient);

        return id;
    }

}
